var logger = require('log4js').getLogger();

var config = require('../../../config');
var register = [];
config.products.map(function(product){
    register[product] = require('../../../sdp.'+product+'/register');
});

var registerType = "register";
var insteadType = "instead";

/**
 *
 * @param input
 *
 * @param register
 * @param next
 * @return
 *
 */
exports.addProject = function(req,res,next){
    var project_type = req.body.project_type;
    var funUrl = "/api/v1/project/project.addProject";
    var registerFunction,registerFunctionType;
    if(register[project_type][funUrl]){
        registerFunction = require('../../..' + register[project_type][funUrl].url)[register[project_type][funUrl].fun];
        registerFunctionType = register[project_type][funUrl].type;
    }

    logger.info("方法类型:"+registerFunctionType);

    if(registerFunctionType == insteadType){
        registerFunction(req,res,next);
    } else {
        logger.info("执行了一些方法blablabla");
        if(registerFunction){
            registerFunction('lalala',function(err){
                if(err){
                    logger.error(err);
                    logger.error("执行注册方法失败");
                    res.json({code:9,msg:"error"});
                    return;
                }
                logger.info("执行注册方法成功");
                res.json({code:0,msg:"执行了注册方法"});
            });
        } else {
            res.json({code:0,msg:"没有执行注册方法"});
        }

    }

}